<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0">
  <title>Grid两列布局 - 右侧Sticky</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      font-family: Arial, sans-serif;
    }

    .container {
      display: grid;
      grid-template-columns: 1fr 300px;
      /* 左列自适应，右列固定宽度 */
      gap: 20px;
      padding: 20px;
      position: relative;
    }

    .left {
      background: #f0f0f0;
      padding: 20px;
    }

    .right {
      background: #cce5ff;
      padding: 20px;
      position: sticky;
      top: 20px;
      /* 距离视口顶部20px */
      height: fit-content;
    }

    .content {
      height: 2000px;
      /* 制造滚动条 */
    }

    .header {
      height: 300px;
      background-color: #bfa
    }

    .bottom {
      height: 1300px;
      background-color: #bfa
    }
  </style>
</head>

<body>

  <div class="header">
    <h2>右边固定</h2>
    <p>我会跟着滚动条在视口固定住！</p>
  </div>
  <div class="container">
    <div class="left">
      <div class="content">
        <h2>左边内容</h2>
        <p>这里是很多很多的内容，页面会有滚动条。</p>
        <p>继续往下滚动可以看到右边栏是sticky的。</p>
        <!-- 更多模拟内容 -->
      </div>
    </div>
    <div class="right">
      <h2>右边固定</h2>
      <p>我会跟着滚动条在视口固定住！</p>
    </div>
  </div>
  <div class="bottom">我是底部</div>
</body>

</html>